home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / PACKED.H < prev    next >
C/C++ Source or Header  |  1993-05-24  |  4KB  |  100 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* packed.h */
  20. /* Packed array format for Ghostscript */
  21.  
  22. /*
  23.  
  24. Packed elements come in 2 different sizes, 2 bytes or 8 bytes.  The
  25. top bits of the first 16-bit subelement distinguish the 2 forms.  The
  26. 'size' of a packed array is the number of elements, not the number of
  27. bytes it occupies.  The encoding:
  28.  
  29.     00tttttt exrwsnm-    full 8-byte object
  30.     010jjjjj jjjjjjjj    executable operator (for bind)
  31.     011vvvvv vvvvvvvv    integer (biased by packed_min_intval)
  32.     10iiiiii iiiiiiii    literal name
  33.     11iiiiii iiiiiiii    executable name
  34.  
  35. The jjj index of executable operators is either the index of the
  36. operator in the op_def_table, if the index is less than op_def_count,
  37. or the index of the definition in the op_array_table (subtracting
  38. op_def_count first).
  39.  
  40. The iii index of names is the one that the name machinery already
  41. maintains.  A name whose index is larger than 16K must be represented
  42. as a full 8-byte element.
  43.  
  44. There are actually two packed array types, t_mixedarray and
  45. t_shortarray.  A t_mixedarray can have a mix of 2- and 8-bit
  46. elements; a t_shortarray has all 2-byte elements.  In both cases, the
  47. `size' is the number of elements.
  48.  
  49. Packed array elements can be distinguished from full-size elements,
  50. so we allow the interpreter to simply execute all the different kinds
  51. of arrays directly.  In theory, this could lead to unaligned accesses
  52. to full-size (8-byte) refs.  Some machines can't handle unaligned
  53. accesses of this kind.  Rather than try to tailor the algorithms to
  54. the machine's capabilities, we guarantee that full-size elements in
  55. mixed arrays are always properly aligned.  We do this by converting
  56. up to 3 preceding 2-byte elements into 8-byte elements so that the
  57. alignment is preserved.  The only code this actually affects is in
  58. make_packed_array.  However, the save/restore machinery in isave.c is
  59. sometimes used to save changes to packed arrays, and it currently
  60. only knows how to save full-size, aligned refs.
  61.  
  62. Note that code in zpacked.c and interp.c knows more about the
  63. representation of packed elements than the definitions in this file
  64. would imply.  Read the code carefully if you change the
  65. representation.
  66.  
  67.  */
  68.  
  69. typedef ushort ref_packed;
  70.  
  71. #define packed_type_shift 13
  72. typedef enum {
  73.     pt_full_ref = 0,
  74. #define pt_min_packed 2
  75.     pt_executable_operator = 2,
  76.     pt_integer = 3,
  77.     pt_literal_name = 4,
  78.     pt_executable_name = 6
  79. } packed_type;
  80. #define pt_tag(pt) ((ref_packed)(pt) << packed_type_shift)
  81. #define r_is_packed(rp)  (*(ref_packed *)(rp) >= pt_tag(pt_min_packed))
  82. #define packed_ref_is_name(prp) (*(prp) >= pt_tag(pt_literal_name))
  83. #define packed_max_full_ref ((2 << packed_type_shift) - 1)
  84. #define packed_min_intval (-(1 << (packed_type_shift - 1)))
  85. #define packed_max_intval ((1 << (packed_type_shift - 1)) - 1)
  86. #define packed_int_mask ((1 << packed_type_shift) - 1)
  87. #define packed_max_name_index ((1 << (packed_type_shift + 1)) - 1)
  88.  
  89. /* Procedures implemented in zpacked.c */
  90. #define packed_per_ref (sizeof(ref) / sizeof(ref_packed))
  91.  
  92. /* Make a packed array */
  93. extern    int    make_packed_array(P4(const ref *, uint, ref *, const char *));
  94.  
  95. /* Get an element from a packed array. */
  96. extern    void    packed_get(P2(const ref_packed *, ref *));
  97. /* Advance to the next element in a packed array. */
  98. #define packed_next(packed)\
  99.   (*packed <= packed_max_full_ref ? packed + packed_per_ref : packed + 1)
  100.